package com.y.fund.domain.com;


import com.y.fund.aacore.abs.IdObj;
import com.y.fund.utils.StrUtil;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
@Table(name="co11_data_code")
@Schema(title ="用于生成递增的数据编号")
public class CO11DataCode extends IdObj {
	
	public final static String DATA_MODEL_DEF = "COMM-";

    @Column(name = "biz_id", length=64, updatable = false, nullable=false)
    @Schema(title = " 业务数据的ID, 前端不传递则系统自动生成")
    private String bizId;

    @Column(name = "data_model", length=32, nullable=false)
    @Schema(title = "要生成编号的业务数据模型约定值，同时也用来作为编号前缀，默认为COMM-")
    private String dataModel;

    @Column(name = "time_range", nullable=false)
    @Schema(title = "要生成编号的业务数据模型约定值，同时也用来作为时间范围，默认为当前的yyyyMM")
    private Integer timeRange;

    @Column(name = "num_val")
    @Schema(title = "此编号的数值部分, 在组成编号时保持一位字母+3位数字，不足时前面补0.如： 001")
    private Integer numVal;

    @Column(name = "full_code", unique = true)
    @Schema(title = "完整的编号，规则为：【dataModel + year + 一位大写字母 + numVal】, 如： SV-2023A001")
    private String fullCode;
    
    public String getFullCode() {
    	if(null == fullCode) {
    		int nval = numVal;
    		String ch = "";
    		if(numVal > 999) {
    			int cnum = numVal / 999;
    			nval = numVal % 999;
    			ch = "" + ((char) (cnum + 64));
    		}
    		
    		
    		fullCode = dataModel + timeRange + ch + StrUtil.FillZeroLeft(""+nval, 3);
    	}
    	return fullCode;
    }
    
}
